package com.example.gc.oams.zpx.voucher.util;

import com.thames.util.StringUtil;

import java.util.Date;
import java.util.UUID;

/**
 * 凭证编号工具类
 *
 * @author Ryan
 */
public final class VoucherUtils {

    /**
     * 时间格式
     */
    public static final String YYYY_MM_DD_HH_MM_SS = "yyyyMMddHHmmss";

    /**
     * 时间格式
     */
    public static final String YYYY_MM_DD_HH_MM_SS_2 = "yyyy-MM-dd HH:mm:ss";

    /**
     * 同步JDE批次号
     *
     * @return JDE批次号
     */
    public static String genJdeBatchCode() {
        StringBuffer sb = new StringBuffer("JDE-");
        sb.append(StringUtil.format(YYYY_MM_DD_HH_MM_SS, new Date()));
        sb.append("-");
        sb.append(UUID.randomUUID().toString().substring(0, 5));

        return sb.toString();
    }

    /**
     * 生成凭证编号
     *
     * @param voucherNo
     * @return
     */
    public static String genAccountVoucherCode(String voucherNo) {
        StringBuffer sb = new StringBuffer(voucherNo);
        sb.append("-");
        sb.append(StringUtil.format(YYYY_MM_DD_HH_MM_SS, new Date()));
        sb.append(UUID.randomUUID().toString().substring(0, 6));

        return sb.toString();
    }

    /**
     * 生成原始数据文件路径
     *
     * @param originDataFileFormat
     * @param voucherMonth
     * @param voucherTypeCode
     * @return
     */
    public static String genOriginDataFilePath(String originDataFileFormat, String voucherMonth, String voucherTypeCode) {
        return String.format(originDataFileFormat, voucherTypeCode, voucherMonth, voucherTypeCode, voucherMonth);
    }

    /**
     * 生成目标SQL文件路径
     *
     * @param targetSQLFilePathFormat
     * @param voucherMonth
     * @param voucherTypeCode
     * @return
     */
    public static String genTargetSQLFilePath(String targetSQLFilePathFormat, String voucherMonth, String voucherTypeCode) {
        return String.format(targetSQLFilePathFormat, voucherTypeCode, voucherMonth, voucherTypeCode, voucherMonth);
    }

    private VoucherUtils(){}
}
